package com.sc.part;

import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

import com.sc.bean.SpendSecond;

/**
 * 
 * @Description 省份分区:下面划分8个分区
 * @author pengjun
 * @version v1.0
 * @date 2020年7月11日
 */
public class CityPart extends Partitioner<Text, SpendSecond> {

	private static Map<String, Integer> city = new HashMap<String, Integer>();
	
	static {
		city.put("江西", 0);
		city.put("广东", 1);
		city.put("北京", 2);
		city.put("江西", 3);
		city.put("湖南", 4);
		city.put("上海", 5);
		city.put("西藏", 6);
	}
	
	/*
	 * 给指定的数据一个分区
	 */
	@Override
	public int getPartition(Text key, SpendSecond value, int numPartitions) {
		// TODO Auto-generated method stub
		Integer c = city.get(value.getCity().toString());
		return c == null ? 7 : c;
	}

}
